#include <bits/stdc++.h>
using namespace std;
const int N = 55;
typedef pair<int, int> pi;
int g[N][N];
int dist[N][N];
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int m, n;
int bfs(int x, int y) {
  dist[x][y] = 0;
  queue<pi> q;
  q.push({x, y});
  int cnt = 0;
  while (q.size()) {
    auto [x, y] = q.front();
    q.pop();
    cnt++;
    for (int i = 0; i < 4; ++i)
      if (!(g[x][y] >> i & 1)) {
        int nx = x + dx[i], ny = y + dy[i];
        if (dist[nx][ny] == -1) {
          dist[nx][ny] = dist[x][y] + 1;
          q.push({nx, ny});
        }
      }
  }
  return cnt;
}
int main() {
  cin >> m >> n;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> g[i][j];
    }
  }
  int res = 0, maxv = 0;
  memset(dist, -1, sizeof dist);
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j)
      if (dist[i][j] == -1) {
        res++;
        maxv = max(maxv, bfs(i, j));
      }

  cout << res << endl << maxv << endl;
}
